﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;

namespace TestWinAPI.任务栏
{
    /// <summary>
    /// ShowWindow 的第二参数， 1 表示显示， 0 表示隐藏
    /// </summary>
    public partial class 任务栏 : System.Web.UI.Page
    {
        [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
            string lpszClass, string lpszWindow);

        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]
        static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);
 
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            //获取任务栏句柄
            IntPtr trayHwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
            //设置任务栏
            if (trayHwnd != IntPtr.Zero)
            {
                if ("显示" == btnShow.Text)
                {
                    btnShow.Text = "隐藏";
                    ShowWindow(trayHwnd, 1);
                }
                else
                {
                    btnShow.Text = "显示";
                    ShowWindow(trayHwnd, 0);
                }
            }
        }


    }
}
